package com.geticsen.leetcode;

public class Solution_45 {
    public int jump(int[] nums) {
        int length = nums.length;
        int[] res = new int[length];
        for (int i = 0; i < length; i++) {
            for (int j = 1; j <= nums[i] && i + j < length; j++) {
                res[i + j] = Math.min(res[i] + 1, res[i+j] == 0 ? Integer.MAX_VALUE : res[i+j]);
            }
        }
        return res[length - 1];
    }

    public static void main(String[] args) {
        Solution_45 solution_45 = new Solution_45();
        int[] nums = {2,3,1,1,4,5,1,1,1,1,1,1,1,1};
        solution_45.jump(nums);
    }
}
